import socket

def main():
    # 创建套接字
    server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    # 绑定端口
    server_socket.bind(('',8090))
    # 变为被动链接
    server_socket.listen(128)
    # 等待客户端的链接
    new_client_socket,addr = server_socket.accept()
    print("来自客户端的链接 %s" % str(addr))

    file_content = None
    try:
        # 接收客户端发送过来的文件名
        recv_data = new_client_socket.recv(1024)
        f = open(recv_data,"rb")
        file_content = f.read()
        f.close()
    except Exception as err:
        print("没有找到这个文件")
    
    # 发送文件数据给客户端
    if file_content:
        new_client_socket.send(file_content)

    # 关闭套接字
    new_client_socket.close()
    server_socket.close()

if __name__ == "__main__":
    main()